<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : teamsComparsionCarts.xsl
    Created on : Pondelok, 2011, máj 10, 20:13
    Author     : peto
    Description:
        Purpose of transformation follows.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" omit-xml-declaration="yes" media-type="html/text"/>
        <xsl:param name="url"/>
        <xsl:param name="team1"/>
        <xsl:param name="team2"/>
        <xsl:param name="loc_team"/>
        <xsl:param name="loc_players"/>
        <xsl:param name="loc_home"/>
        <xsl:param name="loc_guests"/>
        <xsl:param name="loc_score"/>
        <xsl:param name="loc_referee"/>
        <xsl:param name="loc_stadium"/>
        <xsl:param name="loc_spectators"/>
        <xsl:template match="/">
            <table class="teams">
                    <tr>
                    	<td class="l head"><xsl:value-of select="$loc_team"/>&#160;1</td>
                        <td>&#160;</td>
                        <td class="r head"><xsl:value-of select="$loc_team"/>&#160;2</td>
                    </tr>
                    <tr>
                    	<th class="l"><xsl:value-of select="$team1"/></th>
                        <th style="background:transparent;border:none;">&#160;</th>
                        <th class="r"><xsl:value-of select="$team2"/></th>
                    </tr>  
                    <tr>
                    	<td class="l h2"><xsl:value-of select="$loc_players"/></td>
                        <td>&#160;</td>
                        <td class="r h2"><xsl:value-of select="$loc_players"/></td>
                    </tr>
                    <tr>
                    	<td class="l">
                            <xsl:call-template name="homeTeamPlayers">
                                <xsl:with-param name="team" select="$team1" />
                            </xsl:call-template>
                        </td>
                        <td>&#160;</td>
                        <td class="l">
                            <xsl:call-template name="homeTeamPlayers">
                                <xsl:with-param name="team" select="$team2" />
                            </xsl:call-template>
                        </td>
                    </tr>
                </table>
                
                <table class="tmatches">
                        <thead>
                           <tr>
                             <th><xsl:value-of select="$loc_home"/></th>
                             <th><xsl:value-of select="$loc_guests"/></th>
                             <th><xsl:value-of select="$loc_score"/></th>
                             <th><xsl:value-of select="$loc_referee"/></th>
                             <th><xsl:value-of select="$loc_stadium"/></th>
                             <th><xsl:value-of select="$loc_spectators"/></th>
                           </tr>
                       </thead>
                       <tbody>
                        <xsl:call-template name="matches"/>
                       </tbody>
                </table>    
        </xsl:template>
        
        
        <xsl:template name="matches">
            <xsl:for-each select="//match">
                <xsl:variable name="homeScore" select=".//full/@home" />
                <xsl:variable name="guestsScore" select=".//full/@guests" />
                <tr>
                    <xsl:choose>
                        <xsl:when test="$homeScore=$guestsScore">
                            <td class="eq"><xsl:value-of select="./home"/></td> 
                            <td class="eq"><xsl:value-of select="./guests"/></td>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:choose>
                                <xsl:when test="$homeScore &gt; $guestsScore">
                                    <td class="win"><xsl:value-of select="./home"/></td> 
                                    <td class="loss"><xsl:value-of select="./guests"/></td>    
                                    
                                </xsl:when>
                                <xsl:otherwise>
                                    <td class="loss"><xsl:value-of select="./home"/></td> 
                                    <td class="win"><xsl:value-of select="./guests"/></td>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:otherwise>
                    </xsl:choose>              
                   <td>
                       <strong>
                           <xsl:value-of select="$homeScore"/>&#160;-&#160;<xsl:value-of select="$guestsScore"/>
                       </strong>
                       (<xsl:value-of select=".//half/@home"/>-<xsl:value-of select=".//half/@guests"/>)
                   </td> 
                   <td><xsl:value-of select="./referee"/></td>
                   <td><xsl:value-of select="./stadium"/></td>
                   <td><xsl:value-of select="./spectators"/></td>
                </tr> 
            </xsl:for-each>
            
        </xsl:template>
        
        <xsl:template name="homeTeamPlayers">
            <xsl:param name="team"/>
            <xsl:choose>
                <xsl:when test="//match[1]/home=$team">
                        <xsl:for-each select="//match[1]/home-team/player">
                                <xsl:value-of select="current()/@name"/>,&#160;
                        </xsl:for-each>
                </xsl:when>
                <xsl:otherwise>
                         <xsl:for-each select="//match[1]/guest-team/player">
                                <xsl:value-of select="current()/@name"/>,&#160;
                        </xsl:for-each>
                </xsl:otherwise>
            </xsl:choose>    
        </xsl:template>
</xsl:stylesheet>
